package com.mysoft.gfyx.marketdevelop.mip.dto.TjMetric;

import lombok.Data;

import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;

@Data
public class QueryMetricConditionRequestDto {
    private List<String> date_range;
    private QueryMetricConditionWhereRequestDto where;
    private List<QueryMetricConditionGroupRequestDto> group_by;
    private QueryMetricConditionOrderRequestDto indicator_order;

    public QueryMetricConditionRequestDto() {
        date_range = new ArrayList<>();
        date_range.add("2012-01-01");
        date_range.add("2022-06-30");

        group_by = new LinkedList<>();
        where = new QueryMetricConditionWhereRequestDto();
        indicator_order = new QueryMetricConditionOrderRequestDto();
    }

    public void setDate(String startDate, String endDate) {
        date_range.set(0, startDate);
        date_range.set(1, endDate);
    }

    public void addWhere(String tableName, String field, String op, String val, int valType) {
        QueryMetricConditionWhereConditionRequestDto dto = new QueryMetricConditionWhereConditionRequestDto();
        dto.setTable(tableName);
        dto.setField(field);
        dto.setOperate(op);
        dto.setVal(val);
        dto.setVal_type(valType);

        where.getInfo().add(dto);
    }

    public void addGroup(String fieldEnName, String tableName) {
        QueryMetricConditionGroupRequestDto dto = new QueryMetricConditionGroupRequestDto();
        dto.setEn_name(fieldEnName);
        dto.setTable(tableName);

        group_by.add(dto);
    }

    public void addOrder(String orderType) {
        indicator_order.setType(orderType);
    }
}
